package com.npr.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

//@Component
//@Aspect
public class AlphaAspect {
    //切点,只需用注解@Pointcut标注就可以定义切点
    @Pointcut("execution(* com.npr.service.*.*(..))")
    public void pointcut(){

    }
    //切点之前
    @Before("pointcut()")
    public void before(){
        System.out.println("before");
    }
    //切点之后
    @After("pointcut()")
    public void after(){
        System.out.println("after");
    }
    //有返回值之后
    @AfterReturning("pointcut()")
    public void afterReturning(){
        System.out.println("afterReturning");
    }
    //抛出异常时
    @AfterThrowing("pointcut()")
    public void afterThrowing(){
        System.out.println("afterThrowing");
    }
    //在前后都有
    @Around("pointcut()")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        System.out.println("around before");
        //这句话是执行目标的程序，在这句话之前和之后的语句分别是另外需要执行的语句
        Object obj = joinPoint.proceed();
        System.out.println("around after");
        return obj;
    }
}
